<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Tencent_crawl extends CI_Controller {

	/**
	* __construct
	*
	* @access public
	* @return string $mixed
	*/
	public function __construct() {
        parent::__construct();
		ini_set("display_errors","on");
		error_reporting(E_ALL & ~E_NOTICE);
		set_time_limit(0);
		
		$this->load->library('error_code_library');
	}

	/**
	* cookie_test
	*
	* @access public
	* @return string $mixed
	*/
	public function cookie_test() {
		$this->load->helper('form');
		$this->load->view('cookie_test_tencent');
	}

	/**
	* 接收post上来的信息. 测试tencent平台 html抓取
	* 此接口数据不缓存
	*
	* @access public
	* @return string $mixed
	*/
	public function crawl() {
		$_POST['word'] = '回龙观';
		$_POST['platform'] = 'tencent';
		
		$this->load->database();
        $this->load->library('crawl_abstract');
        $this->load->library('crawl_keyword_library');
	    $this->load->library('Crawl_tencent_keyword_from_html_library');

        $html_crawl_result = $this->crawl_tencent_keyword_from_html_library->crawl(true);
        echo "<pre>";
        print_r($html_crawl_result);
        echo "</pre>";
	}
	
	public function crawl_test() {
		$_POST['word'] = '回龙观';
		$_POST['platform'] = 'tencent';
		
		$this->load->database();
        $this->load->library('crawl_abstract');
        $this->load->library('crawl_keyword_library');
	    $this->load->library('Crawl_tencent_keyword_from_html_library');

	    $i = 0;
	    while($i < 50){
	    	echo $i . "\n";
	    	$html_crawl_result = $this->crawl_tencent_keyword_from_html_library->crawl(true);
	    	$i ++;
	    }
	}
	
	public function get_cookie() {
		$this->load->database();
		
		$this->load->model('keyword/Cookie_model');
		$cookie = $this->Cookie_model->get_cookie("tencent");
		print_r($cookie);
	}

	/**
	* crawl_keyword_from_api
	*
	* @access public
	* @param string $charset xxxxx [Must]
	* @param array $contentType xxxxxx [Optional]
	* @param int $display xxxxxxxxx [Optional]
	* @param bool $display xxxxxxxxx [Optional]
	* @return string $mixed
	*/
	public function crawl_keyword_from_api() {
		$post_data = $this->input->post();

		$this->load->database();
        $this->load->library('crawl_abstract');
        $this->load->library('crawl_keyword_library');
	    $this->load->library('Crawl_keyword_from_api_library');

	    $api_crawl_result = $this->crawl_keyword_from_api_library->crawl(TRUE);
		var_dump($api_crawl_result);
	}

	public function crawl_keyword_from_client() {
		//$post_data = $this->input->post();
		$_POST['word'] = '回龙观';
		$_POST['platform'] = 'tencent';

		$this->load->database();
        $this->load->library('crawl_abstract');
        $this->load->library('crawl_keyword_library');
	    $this->load->library('Crawl_tencent_keyword_from_client_library');

	    $api_crawl_result = $this->crawl_tencent_keyword_from_client_library->crawl(false);
		var_dump($api_crawl_result);
	}

	/**
	* test
	*
	* @access public
	* @return string $mixed
	*/
	public function string_test() {
		$this->load->helper('string');
		$sid = random_string('alnum', 24);
		var_dump($sid);

		$qq = random_string('numeric', 9);
		var_dump($qq);
	}
}